<template>

  <!-- 添加或修改岗位对话框 -->
  <el-dialog :title="title" :visible.sync="openshow" width="700px" append-to-body class="my-dialog">
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-row :gutter="10">
        <el-col :span="24">
          <el-form-item label="客户名称" prop="name">
            <el-input v-model="form.name" placeholder="请输入客户名称"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="负责人" prop="contacts">
            <el-input v-model="form.contacts" placeholder="请输入负责人"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="联系电话" prop="phone">
            <el-input v-model="form.phone" placeholder="请输入联系电话"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="纳税人识别号" prop="idCard">
            <el-input v-model="form.invoiceCode" placeholder="请输入纳税人识别号"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="开户行" prop="idCard">
            <el-input v-model="form.bank" placeholder="请输入开户行"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="账号" prop="idCard">
            <el-input v-model="form.bankName" placeholder="请输入账号"/>
          </el-form-item>
        </el-col>
        <!--          <el-col :span="12">-->
        <!--            <el-form-item label="身份证号" prop="idCard">-->
        <!--              <el-input v-model="form.idCard" placeholder="请输入身份证号"/>-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <el-col :span="12">
          <el-form-item label="所在地区" prop="status">
            <el-cascader
              :props="props"
              placeholder="选择所在地址"
              v-model="cascaderData"
              ref="address"
              style="width: 100%"
              @change="handleDep()"
            ></el-cascader>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="地址详情" prop="address">
            <el-input
              type="textarea"
              placeholder="请输入内容"
              v-model="form.address"
              maxlength="30"
              show-word-limit
            >
            </el-input>
          </el-form-item>
        </el-col>
        <!--          <el-col :span="12">-->
        <!--            <el-form-item label="身份证正面照" prop="status">-->
        <!--              <image-upload v-model="form.idFront" :limit="1" :isShowTip="false"/>-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item label="身份证反面照" prop="status">-->
        <!--              <image-upload v-model="form.idBack" :limit="1" :isShowTip="false"/>-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item label="营业执照" prop="status">-->
        <!--              <image-upload v-model="form.license" :limit="1" :isShowTip="false"/>-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm" size="small" plain>确 定</el-button>
      <el-button @click="cancel" size="small">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {getCustom, addCustom, updateCustom} from '@/api/system/custom.js'

export default {
  name: "detailEdit",
  dicts: ['sys_normal_disable'],
  props:['customId', 'visible'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      postList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          {required: true, message: "岗位名称不能为空", trigger: "blur"}
        ],
        contacts: [
          {required: true, message: "岗位编码不能为空", trigger: "blur"}
        ],
        phone: [
          {required: true, message: "岗位顺序不能为空", trigger: "blur"}
        ]
      },

      props: {
        lazy: true,
        label: "name",
        value: "id",
        lazyLoad: this.lazyLoad,
      },
      cascaderData: [], // 地址值
      openshow: false
    };
  },
  watch:{
    visible(){
      // customIdt
      this.openshow =  this.visible
      if(this.customId){
        this.getDetail()
      }
    }
  },
  created() {
  },
  methods: {
    getDetail(){
      getCustom(this.customId).then(response=>{
        if (response.data.provinceId) {
          this.cascaderData = [response.data.provinceId, response.data.cityId, response.data.districtId]
        }
        this.form = response.data;
        this.open = true;
        this.title = "修改客户信息";
      })
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateCustom(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.cancel()
            });
          } else {
            addCustom(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.cancel()
            });
          }
        }
      });
    },
    // 取消按钮
    cancel() {
      this.$emit('getDetail')
      this.$emit('update:visible', false)
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        name: '', // 名称
        contacts: '', //  联系人
        phone: '', //电话
        idCard: '', //身份证号
        idFront: '', //身份证正面
        idBack: '', //身份证反面
        license: '', //营业执照
        address: '', //地址
        provinceId: '', //省id
        province: '', //省
        cityId: '', //市id
        city: '', //市
        districtId: '', //区id
        district: '', // 区
        invoiceCode: '', // 纳税人识别号
        bank: '', // 银行
        bankName: '', // 收款账户
      };
      this.cascaderData = []
      this.resetForm("form");
    },
    // 地址变化徽调
    handleDep(option) {
      let id_ = this.$refs["address"].getCheckedNodes()[0].path;
      let name_ = this.$refs["address"].getCheckedNodes()[0].pathLabels;
      this.form.provinceId = id_[0]
      this.form.cityId = id_[1]
      this.form.districtId = id_[2]
      this.form.province = name_[0]
      this.form.city = name_[1]
      this.form.district = name_[2]
    },
  }
}
</script>

<style scoped>

</style>
